-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connects to Server, Reads Messages #10
base: main
Are you sure you want to change the base?
Conversation
…he configured server ID.
This is an attempt at #8, where we can connect and get meaningful data. I can see the username of messages that are entered in the chat, but not the message contents themselves. Might be a permission thing? |
loop { | ||
match connection.recv_event() { | ||
Ok(Event::MessageCreate(message)) => { | ||
println!("{} says: {}", message.author.name, message.content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we bring in a logging library here?
I'd prefer a structured logging approach that we can hook into various tracing/aggregation tools
match connection.recv_event() { | ||
Ok(Event::MessageCreate(message)) => { | ||
println!("{} says: {}", message.author.name, message.content); | ||
if message.content == "!test" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np
: I'd prefer a constant for these values
// At the top of file
static TEST_CMD: &str = "!test";
fn get_server_id(config: Config) -> u64 { | ||
let num = u64::from_str(config.server_id.as_str()).unwrap(); | ||
return num; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is pretty small, maybe just do this in main
until we have more config values to extract?
fn main() { | ||
let cfg = Config::from_env_and_args(); | ||
let discord = get_discord(cfg.bot_token.as_str()); | ||
let server_id = ServerId(self::get_server_id(cfg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you add the function so that you could wrap the return with ServerId
?
This adds an example
.env
file, that when properly configured, will pull the name of the server for the configured SERVER_ID. Also adds a test for the new config variable.